package com.codedancer.campus.mapper;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.LostFoundItemExamineRecord;
import java.util.List;

public interface LostFoundItemExamineRecordMapper extends BaseMapper<LostFoundItemExamineRecord> {

    /**
     * 查询失物招领审核记录
     *
     * @param lostFoundItemUuid
     * @return
     */
    default List<LostFoundItemExamineRecord> list(String lostFoundItemUuid) {
        LambdaQueryWrapper<LostFoundItemExamineRecord> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(LostFoundItemExamineRecord::getLostFoundItemUuid, lostFoundItemUuid);
        lambdaQueryWrapper.orderByDesc(LostFoundItemExamineRecord::getCreateTime);
        return selectList(lambdaQueryWrapper);
    }

    /**
     * 查询最近一条审核记录
     * @param uuid
     * @return
     */
    default LostFoundItemExamineRecord selectLastExamineRecord(String uuid){
        LambdaQueryWrapper<LostFoundItemExamineRecord> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(LostFoundItemExamineRecord::getLostFoundItemUuid, uuid);
        lambdaQueryWrapper.orderByDesc(LostFoundItemExamineRecord::getCreateTime);
        return CollectionUtil.isNotEmpty(selectList(lambdaQueryWrapper)) ? selectList(
            lambdaQueryWrapper).get(0) : null;
    }
}
